﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Lawyer.Web.Admin
{
    public partial class admin_agencyupdate : System.Web.UI.Page
    {
        Lawyer.BLL.AgencyInfo bll = new Lawyer.BLL.AgencyInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            string ID = InitFromUrl("ID");
            if (ID == "")
            {
                //Response.Redirect("admin_agencylist.aspx");
                Response.Write("parameter lost, please go back!");
            }
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private string InitFromUrl(string url)
        {
            string rtn = Request[url] != null ? Request[url] : "";
            return rtn;
        }
        private void BindData()
        {
            string ID = InitFromUrl("ID");
            Lawyer.Model.AgencyInfo model = bll.GetModel(ID);
            txbAgencyRate.Text = model.AgencyRate.ToString();
            txbEmail.Text = model.Email;
            txbUserName.Text = model.Name;
            txtAddress.Text = model.Address;
            txtCity.Text = model.City;
            txtFax.Text = model.Fax;
            txtTelphone.Text = model.Telphone;
 
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string ID = InitFromUrl("ID");
            Lawyer.Model.AgencyInfo model = bll.GetModel(ID);
            CreateFromForm(model);
            if (bll.Update(model))
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "success！", "admin_agencylist.aspx");
            }
            else
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "failed！", "admin_agencylist.aspx");
            }
        }
        private void CreateFromForm(Lawyer.Model.AgencyInfo model)
        {
            string Name = this.txbUserName.Text;
            string Email = this.txbEmail.Text;
            double AgencyRate = Double.Parse(this.txbAgencyRate.Text);
            string City = this.txtCity.Text;
            string Telphone = this.txtTelphone.Text;
            string Fax = this.txtFax.Text;
            string Address = this.txtAddress.Text;



            model.Name = Name;
            model.Email = Email;
            model.AgencyRate = AgencyRate;
            model.AgencyRate = 0;//初始化
            model.City = City;
            model.Telphone = Telphone;
            model.Fax = Fax;
            model.Address = Address;

            model.Status = 0;//0=>Normal,1=>Deleted
            model.Updatedby = Session["UserID"].ToString();
            model.UpdatedDate = DateTime.Now;


        }
    }
}
